var Base64=function(){
    var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",b={
        encode:function(b){
            var c="",d,e,f,g,h,i,j,k=0;
            do d=b.charCodeAt(k++),e=b.charCodeAt(k++),f=b.charCodeAt(k++),g=d>>2,h=(d&3)<<4|e>>4,i=(e&15)<<2|f>>6,j=f&63,isNaN(e)?i=j=64:isNaN(f)&&(j=64),c=c+a.charAt(g)+a.charAt(h)+a.charAt(i)+a.charAt(j);while(k<b.length);
            return c
        },
        decode:function(b){
            var c="",d,e,f,g,h,i,j,k=0;
            b=b.replace(/[^A-Za-z0-9\+\/\=]/g,"");
            do g=a.indexOf(b.charAt(k++)),h=a.indexOf(b.charAt(k++)),i=a.indexOf(b.charAt(k++)),j=a.indexOf(b.charAt(k++)),d=g<<2|h>>4,e=(h&15)<<4|i>>2,f=(i&3)<<6|j,c=c+String.fromCharCode(d),i!=64&&(c=c+String.fromCharCode(e)),j!=64&&(c=c+String.fromCharCode(f));while(k<b.length);
            return c
        }
    };
    
    return b
}()
var MD5=function(){
    var a=0,b="",c=8,d=function(a,b){
        var c=(a&65535)+(b&65535),d=(a>>16)+(b>>16)+(c>>16);
        return d<<16|c&65535
    },e=function(a,b){
        return a<<b|a>>>32-b
    },f=function(a){
        var b=[],d=(1<<c)-1;
        for(var e=0;e<a.length*c;e+=c)b[e>>5]|=(a.charCodeAt(e/c)&d)<<e%32;
        return b
    },g=function(a){
        var b="",d=(1<<c)-1;
        for(var e=0;e<a.length*32;e+=c)b+=String.fromCharCode(a[e>>5]>>>e%32&d);
        return b
    },h=function(b){
        var c=a?"0123456789ABCDEF":"0123456789abcdef",d="";
        for(var e=0;e<b.length*4;e++)d+=c.charAt(b[e>>2]>>e%4*8+4&15)+c.charAt(b[e>>2]>>e%4*8&15);
        return d
    },i=function(a){
        var c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d="",e,f;
        for(var g=0;g<a.length*4;g+=3){
            e=(a[g>>2]>>8*(g%4)&255)<<16|(a[g+1>>2]>>8*((g+1)%4)&255)<<8|a[g+2>>2]>>8*((g+2)%4)&255;
            for(f=0;f<4;f++)g*8+f*6>a.length*32?d+=b:d+=c.charAt(e>>6*(3-f)&63)
        }
        return d
    },j=function(a,b,c,f,g,h){
        return d(e(d(d(b,a),d(f,h)),g),c)
    },k=function(a,b,c,d,e,f,g){
        return j(b&c|~b&d,a,b,e,f,g)
    },l=function(a,b,c,d,e,f,g){
        return j(b&d|c&~d,a,b,e,f,g)
    },m=function(a,b,c,d,e,f,g){
        return j(b^c^d,a,b,e,f,g)
    },n=function(a,b,c,d,e,f,g){
        return j(c^(b|~d),a,b,e,f,g)
    },o=function(a,b){
        a[b>>5]|=128<<b%32,a[(b+64>>>9<<4)+14]=b;
        var c=1732584193,e=-271733879,f=-1732584194,g=271733878,h,i,j,o;
        for(var p=0;p<a.length;p+=16)h=c,i=e,j=f,o=g,c=k(c,e,f,g,a[p+0],7,-680876936),g=k(g,c,e,f,a[p+1],12,-389564586),f=k(f,g,c,e,a[p+2],17,606105819),e=k(e,f,g,c,a[p+3],22,-1044525330),c=k(c,e,f,g,a[p+4],7,-176418897),g=k(g,c,e,f,a[p+5],12,1200080426),f=k(f,g,c,e,a[p+6],17,-1473231341),e=k(e,f,g,c,a[p+7],22,-45705983),c=k(c,e,f,g,a[p+8],7,1770035416),g=k(g,c,e,f,a[p+9],12,-1958414417),f=k(f,g,c,e,a[p+10],17,-42063),e=k(e,f,g,c,a[p+11],22,-1990404162),c=k(c,e,f,g,a[p+12],7,1804603682),g=k(g,c,e,f,a[p+13],12,-40341101),f=k(f,g,c,e,a[p+14],17,-1502002290),e=k(e,f,g,c,a[p+15],22,1236535329),c=l(c,e,f,g,a[p+1],5,-165796510),g=l(g,c,e,f,a[p+6],9,-1069501632),f=l(f,g,c,e,a[p+11],14,643717713),e=l(e,f,g,c,a[p+0],20,-373897302),c=l(c,e,f,g,a[p+5],5,-701558691),g=l(g,c,e,f,a[p+10],9,38016083),f=l(f,g,c,e,a[p+15],14,-660478335),e=l(e,f,g,c,a[p+4],20,-405537848),c=l(c,e,f,g,a[p+9],5,568446438),g=l(g,c,e,f,a[p+14],9,-1019803690),f=l(f,g,c,e,a[p+3],14,-187363961),e=l(e,f,g,c,a[p+8],20,1163531501),c=l(c,e,f,g,a[p+13],5,-1444681467),g=l(g,c,e,f,a[p+2],9,-51403784),f=l(f,g,c,e,a[p+7],14,1735328473),e=l(e,f,g,c,a[p+12],20,-1926607734),c=m(c,e,f,g,a[p+5],4,-378558),g=m(g,c,e,f,a[p+8],11,-2022574463),f=m(f,g,c,e,a[p+11],16,1839030562),e=m(e,f,g,c,a[p+14],23,-35309556),c=m(c,e,f,g,a[p+1],4,-1530992060),g=m(g,c,e,f,a[p+4],11,1272893353),f=m(f,g,c,e,a[p+7],16,-155497632),e=m(e,f,g,c,a[p+10],23,-1094730640),c=m(c,e,f,g,a[p+13],4,681279174),g=m(g,c,e,f,a[p+0],11,-358537222),f=m(f,g,c,e,a[p+3],16,-722521979),e=m(e,f,g,c,a[p+6],23,76029189),c=m(c,e,f,g,a[p+9],4,-640364487),g=m(g,c,e,f,a[p+12],11,-421815835),f=m(f,g,c,e,a[p+15],16,530742520),e=m(e,f,g,c,a[p+2],23,-995338651),c=n(c,e,f,g,a[p+0],6,-198630844),g=n(g,c,e,f,a[p+7],10,1126891415),f=n(f,g,c,e,a[p+14],15,-1416354905),e=n(e,f,g,c,a[p+5],21,-57434055),c=n(c,e,f,g,a[p+12],6,1700485571),g=n(g,c,e,f,a[p+3],10,-1894986606),f=n(f,g,c,e,a[p+10],15,-1051523),e=n(e,f,g,c,a[p+1],21,-2054922799),c=n(c,e,f,g,a[p+8],6,1873313359),g=n(g,c,e,f,a[p+15],10,-30611744),f=n(f,g,c,e,a[p+6],15,-1560198380),e=n(e,f,g,c,a[p+13],21,1309151649),c=n(c,e,f,g,a[p+4],6,-145523070),g=n(g,c,e,f,a[p+11],10,-1120210379),f=n(f,g,c,e,a[p+2],15,718787259),e=n(e,f,g,c,a[p+9],21,-343485551),c=d(c,h),e=d(e,i),f=d(f,j),g=d(g,o);
        return[c,e,f,g]
    },p=function(a,b){
        var d=f(a);
        d.length>16&&(d=o(d,a.length*c));
        var e=Array(16),g=Array(16);
        for(var h=0;h<16;h++)e[h]=d[h]^909522486,g[h]=d[h]^1549556828;
        var i=o(e.concat(f(b)),512+b.length*c);
        return o(g.concat(i),640)
    },q={
        hexdigest:function(a){
            return h(o(f(a),a.length*c))
        },
        b64digest:function(a){
            return i(o(f(a),a.length*c))
        },
        hash:function(a){
            return g(o(f(a),a.length*c))
        },
        hmac_hexdigest:function(a,b){
            return h(p(a,b))
        },
        hmac_b64digest:function(a,b){
            return i(p(a,b))
        },
        hmac_hash:function(a,b){
            return g(p(a,b))
        },
        test:function(){
            return MD5.hexdigest("abc")==="900150983cd24fb0d6963f7d28e17f72"
        }
    };
    
    return q
}()
Function.prototype.bind||(Function.prototype.bind=function(a){
    var b=this,c=Array.prototype.slice,d=Array.prototype.concat,e=c.call(arguments,1);
    return function(){
        return b.apply(a?a:this,d.call(e,c.call(arguments,0)))
    }
}),Array.prototype.indexOf||(Array.prototype.indexOf=function(a){
    var b=this.length,c=Number(arguments[1])||0;
    c=c<0?Math.ceil(c):Math.floor(c),c<0&&(c+=b);
    for(;c<b;c++)if(c in this&&this[c]===a)return c;return-1
}),function(a){
    function f(a){
        return new b.Builder("presence",a)
    }
    function e(a){
        return new b.Builder("iq",a)
    }
    function d(a){
        return new b.Builder("message",a)
    }
    function c(a,c){
        return new b.Builder(a,c)
    }
    var b;
    b={
        VERSION:"@VERSION@",
        NS:{
            HTTPBIND:"http://jabber.org/protocol/httpbind",
            BOSH:"urn:xmpp:xbosh",
            CLIENT:"jabber:client",
            AUTH:"jabber:iq:auth",
            ROSTER:"jabber:iq:roster",
            PROFILE:"jabber:iq:profile",
            DISCO_INFO:"http://jabber.org/protocol/disco#info",
            DISCO_ITEMS:"http://jabber.org/protocol/disco#items",
            MUC:"http://jabber.org/protocol/muc",
            SASL:"urn:ietf:params:xml:ns:xmpp-sasl",
            STREAM:"http://etherx.jabber.org/streams",
            BIND:"urn:ietf:params:xml:ns:xmpp-bind",
            SESSION:"urn:ietf:params:xml:ns:xmpp-session",
            VERSION:"jabber:iq:version",
            STANZAS:"urn:ietf:params:xml:ns:xmpp-stanzas"
        },
        addNamespace:function(a,c){
            b.NS[a]=c
        },
        Status:{
            ERROR:0,
            CONNECTING:1,
            CONNFAIL:2,
            AUTHENTICATING:3,
            AUTHFAIL:4,
            CONNECTED:5,
            DISCONNECTED:6,
            DISCONNECTING:7,
            ATTACHED:8
        },
        LogLevel:{
            DEBUG:0,
            INFO:1,
            WARN:2,
            ERROR:3,
            FATAL:4
        },
        ElementType:{
            NORMAL:1,
            TEXT:3
        },
        TIMEOUT:1.1,
        SECONDARY_TIMEOUT:.1,
        forEachChild:function(a,c,d){
            var e,f;
            for(e=0;e<a.childNodes.length;e++)f=a.childNodes[e],f.nodeType==b.ElementType.NORMAL&&(!c||this.isTagEqual(f,c))&&d(f)
        },
        isTagEqual:function(a,b){
            return a.tagName.toLowerCase()==b.toLowerCase()
        },
        _xmlGenerator:null,
        _makeGenerator:function(){
            var a;
            window.ActiveXObject?(a=this._getIEXmlDom(),a.appendChild(a.createElement("strophe"))):a=document.implementation.createDocument("jabber:client","strophe",null);
            return a
        },
        xmlGenerator:function(){
            b._xmlGenerator||(b._xmlGenerator=b._makeGenerator());
            return b._xmlGenerator
        },
        _getIEXmlDom:function(){
            var a=null,b=["Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.5.0","Msxml2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","MSXML.DOMDocument","Microsoft.XMLDOM"];
            for(var c=0;c<b.length;c++){
                if(a!==null)break;
                try{
                    a=new ActiveXObject(b[c])
                }catch(d){
                    a=null
                }
            }
            return a
        },
        xmlElement:function(a){
            if(!a)return null;
            var c=b.xmlGenerator().createElement(a),d,e,f;
            for(d=1;d<arguments.length;d++){
                if(!arguments[d])continue;
                if(typeof arguments[d]=="string"||typeof arguments[d]=="number")c.appendChild(b.xmlTextNode(arguments[d]));
                else if(typeof arguments[d]=="object"&&typeof arguments[d].sort=="function")for(e=0;e<arguments[d].length;e++)typeof arguments[d][e]=="object"&&typeof arguments[d][e].sort=="function"&&c.setAttribute(arguments[d][e][0],arguments[d][e][1]);
                else if(typeof arguments[d]=="object")for(f in arguments[d])arguments[d].hasOwnProperty(f)&&c.setAttribute(f,arguments[d][f])
            }
            return c
        },
        xmlescape:function(a){
            a=a.replace(/\&/g,"&amp;"),a=a.replace(/</g,"&lt;"),a=a.replace(/>/g,"&gt;");
            return a
        },
        xmlTextNode:function(a){
            a=b.xmlescape(a);
            return b.xmlGenerator().createTextNode(a)
        },
        getText:function(a){
            if(!a)return null;
            var c="";
            a.childNodes.length===0&&a.nodeType==b.ElementType.TEXT&&(c+=a.nodeValue);
            for(var d=0;d<a.childNodes.length;d++)a.childNodes[d].nodeType==b.ElementType.TEXT&&(c+=a.childNodes[d].nodeValue);
            return c
        },
        copyElement:function(a){
            var c,d;
            if(a.nodeType==b.ElementType.NORMAL){
                d=b.xmlElement(a.tagName);
                for(c=0;c<a.attributes.length;c++)d.setAttribute(a.attributes[c].nodeName.toLowerCase(),a.attributes[c].value);
                for(c=0;c<a.childNodes.length;c++)d.appendChild(b.copyElement(a.childNodes[c]))
            }else a.nodeType==b.ElementType.TEXT&&(d=b.xmlTextNode(a.nodeValue));
            return d
        },
        escapeNode:function(a){
            return a.replace(/^\s+|\s+$/g,"").replace(/\\/g,"\\5c").replace(/ /g,"\\20").replace(/\"/g,"\\22").replace(/\&/g,"\\26").replace(/\'/g,"\\27").replace(/\//g,"\\2f").replace(/:/g,"\\3a").replace(/</g,"\\3c").replace(/>/g,"\\3e").replace(/@/g,"\\40")
        },
        unescapeNode:function(a){
            return a.replace(/\\20/g," ").replace(/\\22/g,'"').replace(/\\26/g,"&").replace(/\\27/g,"'").replace(/\\2f/g,"/").replace(/\\3a/g,":").replace(/\\3c/g,"<").replace(/\\3e/g,">").replace(/\\40/g,"@").replace(/\\5c/g,"\\")
        },
        getNodeFromJid:function(a){
            return a.indexOf("@")<0?null:a.split("@")[0]
        },
        getDomainFromJid:function(a){
            var c=b.getBareJidFromJid(a);
            if(c.indexOf("@")<0)return c;
            var d=c.split("@");
            d.splice(0,1);
            return d.join("@")
        },
        getResourceFromJid:function(a){
            var b=a.split("/");
            if(b.length<2)return null;
            b.splice(0,1);
            return b.join("/")
        },
        getBareJidFromJid:function(a){
            return a?a.split("/")[0]:null
        },
        log:function(a,b){
            return
        },
        debug:function(a){
            this.log(this.LogLevel.DEBUG,a)
        },
        info:function(a){
            this.log(this.LogLevel.INFO,a)
        },
        warn:function(a){
            this.log(this.LogLevel.WARN,a)
        },
        error:function(a){
            this.log(this.LogLevel.ERROR,a)
        },
        fatal:function(a){
            this.log(this.LogLevel.FATAL,a)
        },
        serialize:function(a){
            var c;
            if(!a)return null;
            typeof a.tree=="function"&&(a=a.tree());
            var d=a.nodeName,e,f;
            a.getAttribute("_realname")&&(d=a.getAttribute("_realname")),c="<"+d;
            for(e=0;e<a.attributes.length;e++)a.attributes[e].nodeName!="_realname"&&(c+=" "+a.attributes[e].nodeName.toLowerCase()+"='"+a.attributes[e].value.replace(/&/g,"&amp;").replace(/\'/g,"&apos;").replace(/</g,"&lt;")+"'");
            if(a.childNodes.length>0){
                c+=">";
                for(e=0;e<a.childNodes.length;e++)f=a.childNodes[e],f.nodeType==b.ElementType.NORMAL?c+=b.serialize(f):f.nodeType==b.ElementType.TEXT&&(c+=f.nodeValue);
                c+="</"+d+">"
            }else c+="/>";
            return c
        },
        _requestId:0,
        _connectionPlugins:{},
        addConnectionPlugin:function(a,c){
            b._connectionPlugins[a]=c
        }
    },b.Builder=function(a,c){
        if(a=="presence"||a=="message"||a=="iq")c&&!c.xmlns?c.xmlns=b.NS.CLIENT:c||(c={
            xmlns:b.NS.CLIENT
        });
        this.nodeTree=b.xmlElement(a,c),this.node=this.nodeTree
    },b.Builder.prototype={
        tree:function(){
            return this.nodeTree
        },
        toString:function(){
            return b.serialize(this.nodeTree)
        },
        up:function(){
            this.node=this.node.parentNode;
            return this
        },
        attrs:function(a){
            for(var b in a)a.hasOwnProperty(b)&&this.node.setAttribute(b,a[b]);return this
        },
        c:function(a,c){
            var d=b.xmlElement(a,c);
            this.node.appendChild(d),this.node=d;
            return this
        },
        cnode:function(a){
            var c=b.xmlGenerator(),d=c.importNode?c.importNode(a,!0):b.copyElement(a);
            this.node.appendChild(d),this.node=d;
            return this
        },
        t:function(a){
            var c=b.xmlTextNode(a);
            this.node.appendChild(c);
            return this
        }
    },b.Handler=function(a,c,d,e,f,g,h){
        this.handler=a,this.ns=c,this.name=d,this.type=e,this.id=f,this.options=h||{
            matchbare:!1
        },this.options.matchBare||(this.options.matchBare=!1),this.options.matchBare?this.from=g?b.getBareJidFromJid(g):null:this.from=g,this.user=!0
    },b.Handler.prototype={
        isMatch:function(a){
            var c,d=null;
            this.options.matchBare?d=b.getBareJidFromJid(a.getAttribute("from")):d=a.getAttribute("from"),c=!1;
            if(!this.ns)c=!0;
            else{
                var e=this;
                b.forEachChild(a,null,function(a){
                    a.getAttribute("xmlns")==e.ns&&(c=!0)
                }),c=c||a.getAttribute("xmlns")==this.ns
            }
            return!c||!!this.name&&!b.isTagEqual(a,this.name)||!!this.type&&a.getAttribute("type")!=this.type||!!this.id&&a.getAttribute("id")!=this.id||!!this.from&&d!=this.from?!1:!0
        },
        run:function(a){
            var c=null;
            try{
                c=this.handler(a)
            }catch(d){
                d.sourceURL?b.fatal("error: "+this.handler+" "+d.sourceURL+":"+d.line+" - "+d.name+": "+d.message):d.fileName?(typeof console!="undefined"&&(console.trace(),console.error(this.handler," - error - ",d,d.message)),b.fatal("error: "+this.handler+" "+d.fileName+":"+d.lineNumber+" - "+d.name+": "+d.message)):b.fatal("error: "+this.handler);
                throw d
            }
            return c
        },
        toString:function(){
            return"{Handler: "+this.handler+"("+this.name+","+this.id+","+this.ns+")}"
        }
    },b.TimedHandler=function(a,b){
        this.period=a,this.handler=b,this.lastCalled=(new Date).getTime(),this.user=!0
    },b.TimedHandler.prototype={
        run:function(){
            this.lastCalled=(new Date).getTime();
            return this.handler()
        },
        reset:function(){
            this.lastCalled=(new Date).getTime()
        },
        toString:function(){
            return"{TimedHandler: "+this.handler+"("+this.period+")}"
        }
    },b.Request=function(a,c,d,e){
        this.id=++b._requestId,this.xmlData=a,this.data=b.serialize(a),this.origFunc=c,this.func=c,this.rid=d,this.date=NaN,this.sends=e||0,this.abort=!1,this.dead=null,this.age=function(){
            if(!this.date)return 0;
            var a=new Date;
            return(a-this.date)/1e3
        },this.timeDead=function(){
            if(!this.dead)return 0;
            var a=new Date;
            return(a-this.dead)/1e3
        },this.xhr=this._newXHR()
    },b.Request.prototype={
        getResponse:function(){
            var a=null;
            if(this.xhr.responseXML&&this.xhr.responseXML.documentElement){
                a=this.xhr.responseXML.documentElement;
                if(a.tagName=="parsererror"){
                    b.error("invalid response received"),b.error("responseText: "+this.xhr.responseText),b.error("responseXML: "+b.serialize(this.xhr.responseXML));
                    throw"parsererror"
                }
            }else this.xhr.responseText&&(b.error("invalid response received"),b.error("responseText: "+this.xhr.responseText),b.error("responseXML: "+b.serialize(this.xhr.responseXML)));
            return a
        },
        _newXHR:function(){
            var a=null;
            window.XMLHttpRequest?(a=new XMLHttpRequest,a.overrideMimeType&&a.overrideMimeType("text/xml")):window.ActiveXObject&&(a=new ActiveXObject("Microsoft.XMLHTTP")),a.onreadystatechange=this.func.bind(null,this);
            return a
        }
    },b.Connection=function(a){
        this.service=a,this.jid="",this.rid=Math.floor(Math.random()*4294967295),this.sid=null,this.streamId=null,this.features=null,this.do_session=!1,this.do_bind=!1,this.timedHandlers=[],this.handlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this._idleTimeout=null,this._disconnectTimeout=null,this.authenticated=!1,this.disconnecting=!1,this.connected=!1,this.errors=0,this.paused=!1,this.hold=1,this.wait=60,this.window=5,this._data=[],this._requests=[],this._uniqueId=Math.round(Math.random()*1e4),this._sasl_success_handler=null,this._sasl_failure_handler=null,this._sasl_challenge_handler=null,this._idleTimeout=setTimeout(this._onIdle.bind(this),100);
        for(var c in b._connectionPlugins)if(b._connectionPlugins.hasOwnProperty(c)){
            var d=b._connectionPlugins[c],e=function(){};
        
            e.prototype=d,this[c]=new e,this[c].init(this)
        }
    },b.Connection.prototype={
        reset:function(){
            this.rid=Math.floor(Math.random()*4294967295),this.sid=null,this.streamId=null,this.do_session=!1,this.do_bind=!1,this.timedHandlers=[],this.handlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this.authenticated=!1,this.disconnecting=!1,this.connected=!1,this.errors=0,this._requests=[],this._uniqueId=Math.round(Math.random()*1e4)
        },
        pause:function(){
            this.paused=!0
        },
        resume:function(){
            this.paused=!1
        },
        getUniqueId:function(a){
            return typeof a=="string"||typeof a=="number"?++this._uniqueId+":"+a:++this._uniqueId+""
        },
        connect:function(a,c,d,e,f,g){
            this.jid=a,this.pass=c,this.connect_callback=d,this.disconnecting=!1,this.connected=!1,this.authenticated=!1,this.errors=0,this.wait=e||this.wait,this.hold=f||this.hold,this.domain=b.getDomainFromJid(this.jid);
            var h=this._buildBody().attrs({
                to:this.domain,
                "xml:lang":"en",
                wait:this.wait,
                hold:this.hold,
                content:"text/xml; charset=utf-8",
                ver:"1.6",
                "xmpp:version":"1.0",
                "xmlns:xmpp":b.NS.BOSH
            });
            g&&h.attrs({
                route:g
            }),this._changeConnectStatus(b.Status.CONNECTING,null),this._requests.push(new b.Request(h.tree(),this._onRequestStateChange.bind(this,this._connect_cb.bind(this)),h.tree().getAttribute("rid"))),this._throttledRequestHandler()
        },
        attach:function(a,c,d,e,f,g,h){
            this.jid=a,this.sid=c,this.rid=d,this.connect_callback=e,this.domain=b.getDomainFromJid(this.jid),this.authenticated=!0,this.connected=!0,this.wait=f||this.wait,this.hold=g||this.hold,this.window=h||this.window,this._changeConnectStatus(b.Status.ATTACHED,null)
        },
        xmlInput:function(a){
            return
        },
        xmlOutput:function(a){
            return
        },
        rawInput:function(a){
            return
        },
        rawOutput:function(a){
            return
        },
        send:function(a){
            if(a!==null){
                if(typeof a.sort=="function")for(var b=0;b<a.length;b++)this._queueData(a[b]);else typeof a.tree=="function"?this._queueData(a.tree()):this._queueData(a);
                this._throttledRequestHandler(),clearTimeout(this._idleTimeout),this._idleTimeout=setTimeout(this._onIdle.bind(this),100)
            }
        },
        flush:function(){
            clearTimeout(this._idleTimeout),this._onIdle()
        },
        sendIQ:function(a,b,c,d){
            var e=null,f=this;
            typeof a.tree=="function"&&(a=a.tree());
            var g=a.getAttribute("id");
            g||(g=this.getUniqueId("sendIQ"),a.setAttribute("id",g));
            var h=this.addHandler(function(a){
                e&&f.deleteTimedHandler(e);
                var d=a.getAttribute("type");
                if(d=="result")b&&b(a);
                else if(d=="error")c&&c(a);else throw{
                    name:"StropheError",
                    message:"Got bad IQ type of "+d
                }
            },null,"iq",null,g);
            d&&(e=this.addTimedHandler(d,function(){
                f.deleteHandler(h),c&&c(null);
                return!1
            })),this.send(a);
            return g
        },
        _queueData:function(a){
            if(a===null||!a.tagName||!a.childNodes)throw{
                name:"StropheError",
                message:"Cannot queue non-DOMElement."
            };
    
            this._data.push(a)
        },
        _sendRestart:function(){
            this._data.push("restart"),this._throttledRequestHandler(),clearTimeout(this._idleTimeout),this._idleTimeout=setTimeout(this._onIdle.bind(this),100)
        },
        addTimedHandler:function(a,c){
            var d=new b.TimedHandler(a,c);
            this.addTimeds.push(d);
            return d
        },
        deleteTimedHandler:function(a){
            this.removeTimeds.push(a)
        },
        addHandler:function(a,c,d,e,f,g,h){
            var i=new b.Handler(a,c,d,e,f,g,h);
            this.addHandlers.push(i);
            return i
        },
        deleteHandler:function(a){
            this.removeHandlers.push(a)
        },
        disconnect:function(a){
            this._changeConnectStatus(b.Status.DISCONNECTING,a),b.info("Disconnect was called because: "+a),this.connected&&(this._disconnectTimeout=this._addSysTimedHandler(3e3,this._onDisconnectTimeout.bind(this)),this._sendTerminate())
        },
        _changeConnectStatus:function(a,c){
            for(var d in b._connectionPlugins)if(b._connectionPlugins.hasOwnProperty(d)){
                var e=this[d];
                if(e.statusChanged)try{
                    e.statusChanged(a,c)
                }catch(f){
                    b.error(""+d+" plugin caused an exception "+"changing status: "+f)
                }
            }
            if(this.connect_callback)try{
                this.connect_callback(a,c)
            }catch(g){
                b.error("User connection callback caused an exception: "+g)
            }
        },
        _buildBody:function(){
            var a=c("body",{
                rid:this.rid++,
                xmlns:b.NS.HTTPBIND
            });
            this.sid!==null&&a.attrs({
                sid:this.sid
            });
            return a
        },
        _removeRequest:function(a){
            b.debug("removing request");
            var c;
            for(c=this._requests.length-1;c>=0;c--)a==this._requests[c]&&this._requests.splice(c,1);
            a.xhr.onreadystatechange=function(){},this._throttledRequestHandler()
        },
        _restartRequest:function(a){
            var b=this._requests[a];
            b.dead===null&&(b.dead=new Date),this._processRequest(a)
        },
        _processRequest:function(a){
            var c=this._requests[a],d=-1;
            try{
                c.xhr.readyState==4&&(d=c.xhr.status)
            }catch(e){
                b.error("caught an error in _requests["+a+"], reqStatus: "+d)
            }
            typeof d=="undefined"&&(d=-1);
            if(c.sends>5)this._onDisconnectTimeout();
            else{
                var f=c.age(),g=!isNaN(f)&&f>Math.floor(b.TIMEOUT*this.wait),h=c.dead!==null&&c.timeDead()>Math.floor(b.SECONDARY_TIMEOUT*this.wait),i=c.xhr.readyState==4&&(d<1||d>=500);
                if(g||h||i)h&&b.error("Request "+this._requests[a].id+" timed out (secondary), restarting"),c.abort=!0,c.xhr.abort(),c.xhr.onreadystatechange=function(){},this._requests[a]=new b.Request(c.xmlData,c.origFunc,c.rid,c.sends),c=this._requests[a];
                if(c.xhr.readyState===0){
                    b.debug("request id "+c.id+"."+c.sends+" posting"),c.date=new Date;
                    try{
                        c.xhr.open("POST",this.service,!0)
                    }catch(j){
                        b.error("XHR open failed."),this.connected||this._changeConnectStatus(b.Status.CONNFAIL,"bad-service"),this.disconnect();
                        return
                    }
                    var k=function(){
                        c.xhr.send(c.data)
                    };
                
                    if(c.sends>1){
                        var l=Math.pow(c.sends,3)*1e3;
                        setTimeout(k,l)
                    }else k();
                    c.sends++,this.xmlOutput(c.xmlData),this.rawOutput(c.data)
                }else b.debug("_processRequest: "+(a===0?"first":"second")+" request has readyState of "+c.xhr.readyState)
            }
        },
        _throttledRequestHandler:function(){
            this._requests?b.debug("_throttledRequestHandler called with "+this._requests.length+" requests"):b.debug("_throttledRequestHandler called with undefined requests");
            !!this._requests&&this._requests.length!==0&&(this._requests.length>0&&this._processRequest(0),this._requests.length>1&&Math.abs(this._requests[0].rid-this._requests[1].rid)<this.window&&this._processRequest(1))
        },
        _onRequestStateChange:function(a,c){
            b.debug("request id "+c.id+"."+c.sends+" state changed to "+c.xhr.readyState);
            if(c.abort)c.abort=!1;
            else{
                var d;
                if(c.xhr.readyState==4){
                    d=0;
                    try{
                        d=c.xhr.status
                    }catch(e){}
                    typeof d=="undefined"&&(d=0);
                    if(this.disconnecting&&d>=400){
                        this._hitError(d);
                        return
                    }
                    var f=this._requests[0]==c,g=this._requests[1]==c;
                    if(d>0&&d<500||c.sends>5)this._removeRequest(c),b.debug("request id "+c.id+" should now be removed");
                    if(d==200)(g||f&&this._requests.length>0&&this._requests[0].age()>Math.floor(b.SECONDARY_TIMEOUT*this.wait))&&this._restartRequest(0),b.debug("request id "+c.id+"."+c.sends+" got 200"),a(c),this.errors=0;
                    else{
                        b.error("request id "+c.id+"."+c.sends+" error "+d+" happened");
                        if(d===0||d>=400&&d<600||d>=12e3)this._hitError(d),d>=400&&d<500&&(this._changeConnectStatus(b.Status.DISCONNECTING,null),this._doDisconnect())
                    }
                    d>0&&d<500||c.sends>5||this._throttledRequestHandler()
                }
            }
        },
        _hitError:function(a){
            this.errors++,b.warn("request errored, status: "+a+", number of errors: "+this.errors),this.errors>4&&this._onDisconnectTimeout()
        },
        _doDisconnect:function(){
            b.info("_doDisconnect was called"),this.authenticated=!1,this.disconnecting=!1,this.sid=null,this.streamId=null,this.rid=Math.floor(Math.random()*4294967295),this.connected&&(this._changeConnectStatus(b.Status.DISCONNECTED,null),this.connected=!1),this.handlers=[],this.timedHandlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[]
        },
        _dataRecv:function(a){
            try{
                var c=a.getResponse()
            }catch(d){
                if(d!="parsererror")throw d;
                this.disconnect("strophe-parsererror")
            }
            if(c!==null){
                this.xmlInput(c),this.rawInput(b.serialize(c));
                var e,f;
                while(this.removeHandlers.length>0)f=this.removeHandlers.pop(),e=this.handlers.indexOf(f),e>=0&&this.handlers.splice(e,1);
                while(this.addHandlers.length>0)this.handlers.push(this.addHandlers.pop());
                if(this.disconnecting&&this._requests.length===0){
                    this.deleteTimedHandler(this._disconnectTimeout),this._disconnectTimeout=null,this._doDisconnect();
                    return
                }
                var g=c.getAttribute("type"),h,i;
                if(g!==null&&g=="terminate"){
                    if(this.disconnecting)return;
                    h=c.getAttribute("condition"),i=c.getElementsByTagName("conflict"),h!==null?(h=="remote-stream-error"&&i.length>0&&(h="conflict"),this._changeConnectStatus(b.Status.CONNFAIL,h)):this._changeConnectStatus(b.Status.CONNFAIL,"unknown"),this.disconnect();
                    return
                }
                var j=this;
                b.forEachChild(c,null,function(a){
                    var b,c;
                    c=j.handlers,j.handlers=[];
                    for(b=0;b<c.length;b++){
                        var d=c[b];
                        d.isMatch(a)&&(j.authenticated||!d.user)?d.run(a)&&j.handlers.push(d):j.handlers.push(d)
                    }
                })
            }
        },
        _sendTerminate:function(){
            b.info("_sendTerminate was called");
            var a=this._buildBody().attrs({
                type:"terminate"
            });
            this.authenticated&&a.c("presence",{
                xmlns:b.NS.CLIENT,
                type:"unavailable"
            }),this.disconnecting=!0;
            var c=new b.Request(a.tree(),this._onRequestStateChange.bind(this,this._dataRecv.bind(this)),a.tree().getAttribute("rid"));
            this._requests.push(c),this._throttledRequestHandler()
        },
        _connect_cb:function(a){
            b.info("_connect_cb was called"),this.connected=!0;
            var d=a.getResponse();
            if(!!d){
                this.xmlInput(d),this.rawInput(b.serialize(d));
                var f=d.getAttribute("type"),g,h;
                if(f!==null&&f=="terminate"){
                    g=d.getAttribute("condition"),h=d.getElementsByTagName("conflict"),g!==null?(g=="remote-stream-error"&&h.length>0&&(g="conflict"),this._changeConnectStatus(b.Status.CONNFAIL,g)):this._changeConnectStatus(b.Status.CONNFAIL,"unknown");
                    return
                }
                this.sid||(this.sid=d.getAttribute("sid")),this.stream_id||(this.stream_id=d.getAttribute("authid"));
                var i=d.getAttribute("requests");
                i&&(this.window=parseInt(i,10));
                var j=d.getAttribute("hold");
                j&&(this.hold=parseInt(j,10));
                var k=d.getAttribute("wait");
                k&&(this.wait=parseInt(k,10));
                var l=!1,m=!1,n=!1,o=d.getElementsByTagName("mechanism"),p,q,r,s;
                if(!(o.length>0)){
                    var t=this._buildBody();
                    this._requests.push(new b.Request(t.tree(),this._onRequestStateChange.bind(this,this._connect_cb.bind(this)),t.tree().getAttribute("rid"))),this._throttledRequestHandler();
                    return
                }
                for(p=0;p<o.length;p++)q=b.getText(o[p]),q=="DIGEST-MD5"?m=!0:q=="PLAIN"?l=!0:q=="ANONYMOUS"&&(n=!0);
                b.getNodeFromJid(this.jid)===null&&n?(this._changeConnectStatus(b.Status.AUTHENTICATING,null),this._sasl_success_handler=this._addSysHandler(this._sasl_success_cb.bind(this),null,"success",null,null),this._sasl_failure_handler=this._addSysHandler(this._sasl_failure_cb.bind(this),null,"failure",null,null),this.send(c("auth",{
                    xmlns:b.NS.SASL,
                    mechanism:"ANONYMOUS"
                }).tree())):b.getNodeFromJid(this.jid)===null?(this._changeConnectStatus(b.Status.CONNFAIL,"x-strophe-bad-non-anon-jid"),this.disconnect()):m?(this._changeConnectStatus(b.Status.AUTHENTICATING,null),this._sasl_challenge_handler=this._addSysHandler(this._sasl_challenge1_cb.bind(this),null,"challenge",null,null),this._sasl_failure_handler=this._addSysHandler(this._sasl_failure_cb.bind(this),null,"failure",null,null),this.send(c("auth",{
                    xmlns:b.NS.SASL,
                    mechanism:"DIGEST-MD5"
                }).tree())):l?(r=b.getBareJidFromJid(this.jid),r=r+"",r=r+b.getNodeFromJid(this.jid),r=r+"",r=r+this.pass,this._changeConnectStatus(b.Status.AUTHENTICATING,null),this._sasl_success_handler=this._addSysHandler(this._sasl_success_cb.bind(this),null,"success",null,null),this._sasl_failure_handler=this._addSysHandler(this._sasl_failure_cb.bind(this),null,"failure",null,null),s=Base64.encode(r),this.send(c("auth",{
                    xmlns:b.NS.SASL,
                    mechanism:"PLAIN"
                }).t(s).tree())):(this._changeConnectStatus(b.Status.AUTHENTICATING,null),this._addSysHandler(this._auth1_cb.bind(this),null,null,null,"_auth_1"),this.send(e({
                    type:"get",
                    to:this.domain,
                    id:"_auth_1"
                }).c("query",{
                    xmlns:b.NS.AUTH
                }).c("username",{}).t(b.getNodeFromJid(this.jid)).tree()))
            }
        },
        _sasl_challenge1_cb:function(a){
            var d=/([a-z]+)=("[^"]+"|[^,"]+)(?:,|$)/,e=Base64.decode(b.getText(a)),f=MD5.hexdigest(Math.random()*1234567890),g="",h=null,i="",j="",k;
            this.deleteHandler(this._sasl_failure_handler);
            while(e.match(d)){
                k=e.match(d),e=e.replace(k[0],""),k[2]=k[2].replace(/^"(.+)"$/,"$1");
                switch(k[1]){
                    case"realm":
                        g=k[2];
                        break;
                    case"nonce":
                        i=k[2];
                        break;
                    case"qop":
                        j=k[2];
                        break;
                    case"host":
                        h=k[2]
                }
            }
            var l="xmpp/"+this.domain;
            h!==null&&(l=l+"/"+h);
            var m=MD5.hash(b.getNodeFromJid(this.jid)+":"+g+":"+this.pass)+":"+i+":"+f,n="AUTHENTICATE:"+l,o="";
            o+="username="+this._quote(b.getNodeFromJid(this.jid))+",",o+="realm="+this._quote(g)+",",o+="nonce="+this._quote(i)+",",o+="cnonce="+this._quote(f)+",",o+='nc="00000001",',o+='qop="auth",',o+="digest-uri="+this._quote(l)+",",o+="response="+this._quote(MD5.hexdigest(MD5.hexdigest(m)+":"+i+":00000001:"+f+":auth:"+MD5.hexdigest(n)))+",",o+='charset="utf-8"',this._sasl_challenge_handler=this._addSysHandler(this._sasl_challenge2_cb.bind(this),null,"challenge",null,null),this._sasl_success_handler=this._addSysHandler(this._sasl_success_cb.bind(this),null,"success",null,null),this._sasl_failure_handler=this._addSysHandler(this._sasl_failure_cb.bind(this),null,"failure",null,null),this.send(c("response",{
                xmlns:b.NS.SASL
            }).t(Base64.encode(o)).tree());
            return!1
        },
        _quote:function(a){
            return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'
        },
        _sasl_challenge2_cb:function(a){
            this.deleteHandler(this._sasl_success_handler),this.deleteHandler(this._sasl_failure_handler),this._sasl_success_handler=this._addSysHandler(this._sasl_success_cb.bind(this),null,"success",null,null),this._sasl_failure_handler=this._addSysHandler(this._sasl_failure_cb.bind(this),null,"failure",null,null),this.send(c("response",{
                xmlns:b.NS.SASL
            }).tree());
            return!1
        },
        _auth1_cb:function(a){
            var c=e({
                type:"set",
                id:"_auth_2"
            }).c("query",{
                xmlns:b.NS.AUTH
            }).c("username",{}).t(b.getNodeFromJid(this.jid)).up().c("password").t(this.pass);
            b.getResourceFromJid(this.jid)||(this.jid=b.getBareJidFromJid(this.jid)+"/strophe"),c.up().c("resource",{}).t(b.getResourceFromJid(this.jid)),this._addSysHandler(this._auth2_cb.bind(this),null,null,null,"_auth_2"),this.send(c.tree());
            return!1
        },
        _sasl_success_cb:function(a){
            b.info("SASL authentication succeeded."),this.deleteHandler(this._sasl_failure_handler),this._sasl_failure_handler=null,this._sasl_challenge_handler&&(this.deleteHandler(this._sasl_challenge_handler),this._sasl_challenge_handler=null),this._addSysHandler(this._sasl_auth1_cb.bind(this),null,"stream:features",null,null),this._sendRestart();
            return!1
        },
        _sasl_auth1_cb:function(a){
            this.features=a;
            var c,d;
            for(c=0;c<a.childNodes.length;c++)d=a.childNodes[c],d.nodeName=="bind"&&(this.do_bind=!0),d.nodeName=="session"&&(this.do_session=!0);
            if(!this.do_bind){
                this._changeConnectStatus(b.Status.AUTHFAIL,null);
                return!1
            }
            this._addSysHandler(this._sasl_bind_cb.bind(this),null,null,null,"_bind_auth_2");
            var f=b.getResourceFromJid(this.jid);
            f?this.send(e({
                type:"set",
                id:"_bind_auth_2"
            }).c("bind",{
                xmlns:b.NS.BIND
            }).c("resource",{}).t(f).tree()):this.send(e({
                type:"set",
                id:"_bind_auth_2"
            }).c("bind",{
                xmlns:b.NS.BIND
            }).tree());
            return!1
        },
        _sasl_bind_cb:function(a){
            if(a.getAttribute("type")=="error"){
                b.info("SASL binding failed."),this._changeConnectStatus(b.Status.AUTHFAIL,null);
                return!1
            }
            var c=a.getElementsByTagName("bind"),d;
            if(c.length>0)d=c[0].getElementsByTagName("jid"),d.length>0&&(this.jid=b.getText(d[0]),this.do_session?(this._addSysHandler(this._sasl_session_cb.bind(this),null,null,null,"_session_auth_2"),this.send(e({
                type:"set",
                id:"_session_auth_2"
            }).c("session",{
                xmlns:b.NS.SESSION
            }).tree())):(this.authenticated=!0,this._changeConnectStatus(b.Status.CONNECTED,null)));
            else{
                b.info("SASL binding failed."),this._changeConnectStatus(b.Status.AUTHFAIL,null);
                return!1
            }
        },
        _sasl_session_cb:function(a){
            if(a.getAttribute("type")=="result")this.authenticated=!0,this._changeConnectStatus(b.Status.CONNECTED,null);
            else if(a.getAttribute("type")=="error"){
                b.info("Session creation failed."),this._changeConnectStatus(b.Status.AUTHFAIL,null);
                return!1
            }
            return!1
        },
        _sasl_failure_cb:function(a){
            this._sasl_success_handler&&(this.deleteHandler(this._sasl_success_handler),this._sasl_success_handler=null),this._sasl_challenge_handler&&(this.deleteHandler(this._sasl_challenge_handler),this._sasl_challenge_handler=null),this._changeConnectStatus(b.Status.AUTHFAIL,null);
            return!1
        },
        _auth2_cb:function(a){
            a.getAttribute("type")=="result"?(this.authenticated=!0,this._changeConnectStatus(b.Status.CONNECTED,null)):a.getAttribute("type")=="error"&&(this._changeConnectStatus(b.Status.AUTHFAIL,null),this.disconnect());
            return!1
        },
        _addSysTimedHandler:function(a,c){
            var d=new b.TimedHandler(a,c);
            d.user=!1,this.addTimeds.push(d);
            return d
        },
        _addSysHandler:function(a,c,d,e,f){
            var g=new b.Handler(a,c,d,e,f);
            g.user=!1,this.addHandlers.push(g);
            return g
        },
        _onDisconnectTimeout:function(){
            b.info("_onDisconnectTimeout was called");
            var a;
            while(this._requests.length>0)a=this._requests.pop(),a.abort=!0,a.xhr.abort(),a.xhr.onreadystatechange=function(){};
        
            this._doDisconnect();
            return!1
        },
        _onIdle:function(){
            var a,c,d,e;
            while(this.addTimeds.length>0)this.timedHandlers.push(this.addTimeds.pop());
            while(this.removeTimeds.length>0)c=this.removeTimeds.pop(),a=this.timedHandlers.indexOf(c),a>=0&&this.timedHandlers.splice(a,1);
            var f=(new Date).getTime();
            e=[];
            for(a=0;a<this.timedHandlers.length;a++){
                c=this.timedHandlers[a];
                if(this.authenticated||!c.user)d=c.lastCalled+c.period,d-f<=0?c.run()&&e.push(c):e.push(c)
            }
            this.timedHandlers=e;
            var g,h;
            this.authenticated&&this._requests.length===0&&this._data.length===0&&!this.disconnecting&&(b.info("no requests during idle cycle, sending blank request"),this._data.push(null));
            if(this._requests.length<2&&this._data.length>0&&!this.paused){
                g=this._buildBody();
                for(a=0;a<this._data.length;a++)this._data[a]!==null&&(this._data[a]==="restart"?g.attrs({
                    to:this.domain,
                    "xml:lang":"en",
                    "xmpp:restart":"true",
                    "xmlns:xmpp":b.NS.BOSH
                }):g.cnode(this._data[a]).up());
                delete this._data,this._data=[],this._requests.push(new b.Request(g.tree(),this._onRequestStateChange.bind(this,this._dataRecv.bind(this)),g.tree().getAttribute("rid"))),this._processRequest(this._requests.length-1)
            }
            this._requests.length>0&&(h=this._requests[0].age(),this._requests[0].dead!==null&&this._requests[0].timeDead()>Math.floor(b.SECONDARY_TIMEOUT*this.wait)&&this._throttledRequestHandler(),h>Math.floor(b.TIMEOUT*this.wait)&&(b.warn("Request "+this._requests[0].id+" timed out, over "+Math.floor(b.TIMEOUT*this.wait)+" seconds since last activity"),this._throttledRequestHandler())),clearTimeout(this._idleTimeout),this._idleTimeout=setTimeout(this._onIdle.bind(this),100)
        }
    },a&&a(b,c,d,e,f)
}(function(){
    window.Strophe=arguments[0],window.$build=arguments[1],window.$msg=arguments[2],window.$iq=arguments[3],window.$pres=arguments[4]
})
